﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using RedBit.OAuthLibrary.Twitter;

namespace RedBit.WindowsPhone.Samples
{
    public static class ApplicationSettings
    {

        private static string m_twitterOAuthKey = "twitterOAuth";
        public static TwitterOAuth TwitterOAuthAppSettings
        {
            get
            {
                return GetKeyValue<TwitterOAuth>(m_twitterOAuthKey);
            }
            set
            {
                SetKeyValue(m_twitterOAuthKey, value);
            }
        }

        private static T GetKeyValue<T>(string key)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
                return (T)IsolatedStorageSettings.ApplicationSettings[key];
            else
                return default(T);
        }

        private static void SetKeyValue<T>(string key, T value)
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
                IsolatedStorageSettings.ApplicationSettings[key] = value;
            else
                IsolatedStorageSettings.ApplicationSettings.Add(key, value);

            IsolatedStorageSettings.ApplicationSettings.Save();
        }
    }
}
